<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <canvas id="c1" width="600" height="400"></canvas>

    <script>
        /** @type {HTMLCanvasElement} */
        // 画布
        let c1 = document.getElementById("c1")
        // 画笔
        let ctx = c1.getContext("2d")
        // 全局透明度
        ctx.globalAlpha = 0.4

        // 保存路径
        let heartPath = new Path2D()
        heartPath.moveTo(300, 200)
        heartPath.bezierCurveTo(350, 150, 400, 200, 300, 300)
        heartPath.bezierCurveTo(200, 200, 250, 150, 300, 200)

        // 传递路径给画笔
        ctx.fillStyle = "rgba(160,60,60,.6)"
        ctx.fill(heartPath)

        let chatPath = new Path2D()
        chatPath.moveTo(200, 300)
        chatPath.quadraticCurveTo(150, 300, 150, 200)
        chatPath.quadraticCurveTo(150, 100, 300, 100)
        chatPath.quadraticCurveTo(450, 100, 450, 200)
        chatPath.quadraticCurveTo(450, 300, 250, 300)
        chatPath.quadraticCurveTo(250, 350, 150, 350)
        chatPath.quadraticCurveTo(200, 350, 200, 300)
        ctx.strokeStyle = "red"
        ctx.stroke(chatPath)

        // svg写法
        let polyline = new Path2D("M10 10 h 80 v 80 h -80 z")
        ctx.strokeStyle = "#ff00ff"
        ctx.stroke(polyline)

    </script>
</body>

</html>